# -*- coding: utf-8 -*-
# File : get_sys_env.py
# Author: taoyahui
# Date : 2021/4/20
from utils.ansible_util import *
from utils.path_util import *


def get_sys_env(ip, username, passwd, port):
    hosts = {'t_g': {'hosts': [{'ip': ip, 'username': username, 'password': passwd, 'port': port}]}}
    mi = MyInventory()
    mi._dynamic_inventory(hosts)
    ansible = MyAnsiable(inventory=mi._inventory, connection='smart')
    extra_var = {
        'host': ip,
        'username': username,
    }
    abs_path = get_root_dir()
    ansible.playbook(playbooks=[abs_path + '/playbook/sys_param.yml'], var=extra_var)
    result = ansible.get_result()
    return result


if __name__ == '__main__':
    get_sys_env('10.16.81.153', 'root', '123456', 60122)